import http from '@/api/axios'
// import { key as apiKey } from '@/api/base'
const apiKey = '195a9b99ea7a0d259151b5c412bb631b'

// sign获取接口
const getSign = ({ code, origin, type }) =>
  http.post('actionWeiXinAuth', {
    api_key: apiKey,
    origin,
    type,
    code
  })

export default {
  setLoginStatus ({ commit }, loginStatus) {
    commit('setLoginStatus', loginStatus)
  },
  async loginWechatAuth ({ commit }, code) {
    let host = window.location.host
    const type = host.split('.')[0].match('test') ? 2 : 1
    const origin = /hpl/.test(host) ? 1 : /ydn/.test(host) ? 2 : 3
    const res = await getSign({
      code,
      origin,
      type
    })
    commit('setWxSign', res.data.sign)
    return res.data
  }
}
